<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var str = prompt("请输入想要查找的文章");
        var s = prompt("请输入想要查找的字");

        document.write(findSubString(str, s));


        function findSubString(str, s) {
            var index = str.indexOf(s);
            // alert(index);
            var count = 0;
            while (index != -1) {
                count++;
                index = str.indexOf(s, index + 1);
                //return count; 
            }
            return count;
        }
    </script>


</body>

</html>